package com.gydz.gydzbaseframeworkboot.SystemControl.service.impl;

import com.gydz.gydzbaseframeworkboot.SystemControl.dao.ShortcutMenuMapper;
import com.gydz.gydzbaseframeworkboot.SystemControl.domain.ShortcutMenu;
import com.gydz.gydzbaseframeworkboot.SystemControl.service.ShortcutMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 快捷菜单服务层实现
 * @author caiwf
 */
@Service
public class ShortcutMenuServiceImpl implements ShortcutMenuService {

    @Autowired
    private ShortcutMenuMapper shortcutMenuMapper;

    @Override
    public List<ShortcutMenu> list(ShortcutMenu shortcutMenu) {
        return shortcutMenuMapper.list(shortcutMenu);
    }

    @Override
    public ShortcutMenu findByUserId(Long userId) {
        return shortcutMenuMapper.findByUserId(userId);
    }

    @Override
    public ShortcutMenu save(ShortcutMenu shortcutMenu) {

        if (shortcutMenuMapper.findByUserId(shortcutMenu.getUserId()) == null) {
            shortcutMenuMapper.insert(shortcutMenu);
        } else {
            shortcutMenuMapper.update(shortcutMenu);
        }
        return shortcutMenu;
    }

    @Override
    public void deleteById(Long id) {
        shortcutMenuMapper.deleteById(id);
    }
}
